package org.abratuhi.kvngroupware.client.widget;

import java.awt.Dimension;

import javax.swing.SwingUtilities;

import org.abratuhi.kvngroupware.client.model.KVNGroupwareClient;
import org.abratuhi.kvngroupware.widget.AbstractWorkWidget;
import org.jdom.Element;

@SuppressWarnings("serial")
public class GuiRoot extends AbstractWorkWidget{
	
	KVNGroupwareClient kvnclient = new KVNGroupwareClient();
	
	GuiRootMenubar menubar;
	
	public GuiRoot(){
		super("login", "KVNGroupware Client", null, null);
		
		sender = kvnclient;
		locale = kvnclient.locale;
		
		setPreferredSize(new Dimension(200, 50));
		menubar = new GuiRootMenubar(sender, locale, 
				kvnclient.loginmanager, kvnclient.regmanager, kvnclient.usermanager, 
				kvnclient.chatroommanager, kvnclient.brainstormmanager, 
				kvnclient.scenariomanager, kvnclient.jokemanager, kvnclient.dalgenmanager, 
				kvnclient.widgetmanager);
	}
	
	public void createWindow(){
		super.createWindow();
		frame.setJMenuBar(menubar);
		frame.pack();
	}
	
	public void onFrameClose(){
		sender.sendMessage(
				sender.createMessage("type,action", "user,logout", "",
						new Element[]{kvnclient.loginmanager.getUser().toElement()}));
		System.exit(0);
	}
	
	public static void main(String[] args){
		SwingUtilities.invokeLater(new Runnable(){
			@Override
			public void run(){
				GuiRoot guiroot = new GuiRoot();
				guiroot.kvnclient.widgetmanager.put("root", guiroot);
				guiroot.kvnclient.start();
				guiroot.createWindow();
			}
		});
	}

}
